package com.akk.module.avs.service;

import com.akk.module.avs.entity.AvsPayCashBind;
import com.akk.module.avs.entity.AvsPayCashBindExample;
import com.akk.module.avs.mapper.AvsPayCashBindMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AvsPayCashBindService {

    @Autowired
    AvsPayCashBindExample avsPayCashBindExample;
    @Autowired
    AvsPayCashBindMapper avsPayCashBindMapper;


    public List<AvsPayCashBind> findByPayerIdAndToken(String payerId,String token){
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andTokenEqualTo(token);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public List<AvsPayCashBind> findByCardNum(String cardNum) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andCardNumEqualTo(cardNum);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public List<AvsPayCashBind> findByPayerId(String payerId) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public AvsPayCashBind findById(String bindId){
        return avsPayCashBindMapper.selectByPrimaryKey(bindId);
    }

    public List<AvsPayCashBind> findByCardNumAndPayerId(String cardNum, String payerId) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andCardNumEqualTo(cardNum);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public void save(AvsPayCashBind avsPayCardBind) {
        avsPayCashBindMapper.insert(avsPayCardBind);
    }

    public void deleteByCashBindId(String cashBindId) {
        avsPayCashBindMapper.deleteByPrimaryKey(cashBindId);
    }

    public List<AvsPayCashBind> findByCashBinIdAndPayerId(String cashBindId, String payerId) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andCashBindIdEqualTo(cashBindId);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public List<AvsPayCashBind> findByIsDepositAndPayerId(int i, String payerId) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andIsDepositEqualTo(i).andPayerIdEqualTo(payerId);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public void update(AvsPayCashBind cashBindIsDeposit) {
        avsPayCashBindMapper.updateByPrimaryKey(cashBindIsDeposit);
    }

    public void resetDeposit(String payerId){
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andIsDepositEqualTo(1);
        AvsPayCashBind cashBind = new AvsPayCashBind();
        cashBind.setIsDeposit(0);
        avsPayCashBindMapper.updateByExampleSelective(cashBind,avsPayCashBindExample);
    }

    public List<AvsPayCashBind> findByCashBinIdAndPayerIdAndIsDeposit(String payerId, String cashBindId,Integer i) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andCashBindIdEqualTo(cashBindId).andIsDepositEqualTo(i);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }

    public List<AvsPayCashBind> findByCashBinIdAndIsDeposit(String payerId, int i) {
        avsPayCashBindExample.clear();
        avsPayCashBindExample.createCriteria().andPayerIdEqualTo(payerId).andIsDepositEqualTo(i);
        return avsPayCashBindMapper.selectByExample(avsPayCashBindExample);
    }
}
